package com.xc.quickstart.manager.wechat;

import com.xc.quickstart.common.annotation.LogAround;
import com.xc.quickstart.manager.wechat.model.QyWechatCode2SessionResponseModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.context.annotation.Bean;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@FeignClient(value = "qyapi-client", url = "${qywechat.uri.path}", configuration = QyWechatClient.QyApiClientConfig.class)
interface QyWechatClient {

    @Slf4j
    class QyApiClientConfig {

        @Bean
        //配置打印日志
        public feign.Logger.Level multipartLoggerLevel() {
            return feign.Logger.Level.FULL;
        }

    }

    /**
     * 获取access_token
     *
     * @param
     * @return
     */
    @LogAround
    @GetMapping(value = "/cgi-bin/gettoken", consumes = MediaType.APPLICATION_JSON_VALUE)
    Object getAccessToken(@RequestParam("corpid") String corpid,
                          @RequestParam("corpsecret") String corpsecret);

    /**
     * 临时登录凭证校验
     *
     * @param accessToken
     * @param jsCode
     * @param grantType
     * @return
     */
    @LogAround
    @GetMapping(value = "/cgi-bin/miniprogram/jscode2session", consumes = MediaType.APPLICATION_JSON_VALUE)
    QyWechatCode2SessionResponseModel code2Session(@RequestParam("access_token") String accessToken,
                                                   @RequestParam("js_code") String jsCode,
                                                   @RequestParam("grant_type") String grantType);
}
